package org.example;

import com.alibaba.cloud.nacos.NacosConfigManager;
import com.alibaba.nacos.api.config.listener.Listener;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

@EnableDiscoveryClient      //开启服务发现的功能
@EnableFeignClients         //开启feign客户端功能
@SpringBootApplication
public class Order {
    public static void main(String[] args) {
        SpringApplication.run(Order.class,args);
    }

    @Bean
    ApplicationRunner applicationRunner(NacosConfigManager nacosConfigManager){
        return  ars -> {
            nacosConfigManager.getConfigService().addListener("service-order.properties", "DEFAULT_GROUP", new Listener() {

                @Override
                public Executor getExecutor() {
                    return Executors.newFixedThreadPool(4);
                }

                @Override
                public void receiveConfigInfo(String s) {
                    System.out.println("变化的配置信息:" + s);
                }
            });
            System.out.println("项目启动监听配置中心配置的变化");
        };
    }
}